<template>
	<view style="padding: 5px 10px;">
		<view class="flex" style="margin-top: 10rpx;">
			<view class="biao" style="width: 100%;">
				<span class="biao_span1">2</span>
				<text class="cardTitle">{{text.goods_filelist}} </text>
				<view v-if="loading" style="float: right;">
					<view class="order_info_btn orange" style="float: right;"  v-if="dqr" @click="hwqd()">{{$t("待确认")}}</view>
					<view class="order_info_btn green" style="float: right;" v-if="yqr">{{$t("已确认")}}</view>
					<view class="order_info_btn orange" style="float: right;" :class="plat=='app'?'touming':''" v-if="scbtn">
						<view v-if="plat=='app'"><upload v-if="plat=='app'" @change="upload" :text="text.upload"></upload></view>
						<view v-if="plat!='app'"><formFiles3 v-if="plat!='app'" :item="{}" :showDataList="[]" :color="'white'" :text="text.upload" @change="upload">
						</formFiles3></view>
					</view>
					

					<!-- <block v-if="yqr">
						<view class="order_info_btn green" style="float: right;"
						v-if="ysc">{{$t("已确认")}}</view>
					</block> -->
						
						
				</view>
				<view style="clear: both;"></view>
			</view>
		</view>

		<view class="buy_files" v-if="order.orderInfo.goods_list">
			<view style="padding: 5px 10px;" class="downLoad" @click="hwqd()"> 
				{{ order.orderInfo.goods_list.substring(order.orderInfo.goods_list.length, order.orderInfo.goods_list.length - 20) }}
			</view>
		</view>
		<view class="buy_files" v-else-if="order.orderJoin.goods_list">
			<view style="padding: 5px 10px;" class="downLoad" @click="hwqd()">
				{{ order.orderJoin.goods_list.substring(order.orderJoin.goods_list.length, order.orderJoin.goods_list.length - 20) }}
			</view>
		</view>
		<view style="margin-left: 3%;font-size: 12px;margin-top: 10px;" v-else>
			{{$t("暂未上传")}}
		</view>
		<view style="float: left;color: red;margin-bottom: 5%;font-size: 10px;margin-left: 10px;" v-if="ddfqr">
			{{$t("待对方确认")}}
		</view>
		<view style="float: left;color: rgb(56, 222, 106);margin-bottom: 5%;font-size: 10px;margin-left: 10px;" v-if="dfyqr" @click="hwqd()">
			{{$t("对方已确认")}}
		</view>
		<view style="height: 10rpx;width: 100%;"></view>
	</view>
</template>

<script>
	import {
		HTTP_REQUEST_URL,
		HTTP_IMG_UTL,
		IMAGE_URL
	} from "@/config/app";
	import formFiles3 from '../formFiles3.vue';
	import upload from "@/components/buildForm/upload.vue";
	
	export default {
		components: {
			formFiles3,upload
		},
		props: {
			order2: {
				type: [Array, Object, Number, String],
				default: ''
			},
		},
		data() {
			return {
				//远程域名
				HTTP_IMG_UTL,
				HTTP_REQUEST_URL,
				IMAGE_URL,
				url: IMAGE_URL,
				plat:uni.getStorageSync('plat'),

				//语言
				lang: this.$i18n.locale,
				order: {
					orderJoin: {
						goods_list: '',
					},
					orderInfo: {
						goods_list: '',
					}
				},
				//文字
				text: {
					goods_filelist: this.$t('货物清单'),
					yiqueren: this.$t('已确认'),
					upload: this.$t('上传'),
				},
				//货物清单
				goods_list: '',
				loading: false,
				yqr: false,
				dfyqr: false,
				scbtn:false,
				ysc:false,
				ddfqr:false,
				dqr:false,
			}
		},
		mounted() {
			this.order = this.order2
			if (this.order) {
				this.goods_list = this.order.orderJoin.goods_list
			}
			if (this.order.orderInfo.goods_list && this.order.role == 1 && this.order.orderJoin.is_goodslist == 0) {
				this.text.upload = this.$t("重新上传");
			} else if (this.order.orderJoin.goods_list && this.order.role == 2 && this.order.orderInfo.is_goodslist == 0) {
				this.text.upload = this.$t("重新上传");
			}
			this.yiqueren()
			this.duifangyiqueren()
			this.sc_btn()
			this.yishangchuan()
			this.daiduifangqueren()
			this.daiqueren()
			this.plat = uni.getStorageSync('plat')
			if (!this.plat) {
				uni.getSystemInfo({
					success: function(res) {
						if(res){
							if (res.uniPlatform === 'app') {
								this.plat = 'app'
							} else if (res.uniPlatform === 'web') {
								this.plat = 'web'
							} else if (res.uniPlatform === 'mp-weixin') {
								this.plat = 'mp-weixin'
							}
							uni.setStorage({
								key: 'plat',
								data: this.plat
							})
							this.plat = uni.getStorageSync('plat')
						}
					}
				})
			}
			this.loading = true
		},
		
		methods: {
			sc_btn(){
				if(this.order.orderInfo.type == 'goods'&&(this.order.orderInfo.is_goodslist==0||this.order.orderJoin.is_goodslist==0)&&this.order.role==2){
					this.scbtn=true;
				}else if(this.order.orderInfo.type == 'crossborder'&&(this.order.orderJoin.is_goodslist==0||this.order.orderInfo.is_goodslist==0)&&this.order.role==1){
					this.scbtn=true;
				}else if(this.order.orderInfo.type == 'transport'&&(this.order.orderJoin.is_goodslist==0||this.order.orderInfo.is_goodslist==0)&&this.order.role==2&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.human_type==2&&this.order.orderInfo.release_info.release_type==3))){
					this.scbtn=true;
				}else if(this.order.orderInfo.type == 'transport'&(this.order.orderJoin.is_goodslist==0||this.order.orderInfo.is_goodslist==0)&&this.order.role==1&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.human_type==1&&this.order.orderInfo.release_info.release_type==3))){
					this.scbtn=true;
				}
			},
			yishangchuan(){
				if(this.order.orderInfo.type == 'goods'&&this.order.orderJoin.goods_list&&this.order.role==2){
					this.ysc=true;
				}else if(this.order.orderInfo.type == 'crossborder'&&this.order.orderInfo.goods_list&&this.order.role==1){
					this.ysc=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.goods_list&&this.order.role==2&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.human_type==2&&this.order.orderInfo.release_info.release_type==3))){
					this.ysc=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderInfo.goods_list&&this.order.role==1&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.human_type==1&&this.order.orderInfo.release_info.release_type==3))){
					this.ysc=true;
				}
			},
			daiduifangqueren(){
				if(this.order.orderInfo.type == 'goods'&&this.order.orderJoin.goods_list&&this.order.role==2&&this.order.orderInfo.is_goodslist==0){
					this.ddfqr=true;
				}else if(this.order.orderInfo.type == 'goods'&&this.order.orderInfo.goods_list&&this.order.role==1&&this.order.orderJoin.is_goodslist==0){
					this.ddfqr=true;
				}else if(this.order.orderInfo.type == 'crossborder'&&this.order.orderInfo.goods_list&&this.order.role==1&&this.order.orderJoin.is_goodslist==0){
					this.ddfqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.goods_list&&this.order.role==2&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.human_type==2&&this.order.orderInfo.release_info.release_type==3))&&this.order.orderInfo.is_goodslist==0){
					this.ddfqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderInfo.goods_list&&this.order.role==1&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.human_type==1&&this.order.orderInfo.release_info.release_type==3))&&this.order.orderJoin.is_goodslist==0){
					this.ddfqr=true;
				}
			},
			daiqueren(){
				if(this.order.orderInfo.type == 'goods'&&this.order.orderInfo.is_goodslist==0&&this.order.orderJoin.is_goodslist==1&&this.order.role==1){
					this.dqr=true;
					this.loading=true;
				}else if(this.order.orderInfo.type == 'goods'&&this.order.orderJoin.is_goodslist==0&&this.order.role==2){
					this.dqr=false;
					this.loading=true;
				}else if(this.order.orderInfo.type == 'crossborder'&&this.order.orderInfo.is_goodslist==1&&this.order.orderJoin.is_goodslist==0&&this.order.role==2){
					this.dqr=true;
					this.loading=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderInfo.is_goodslist==0&&this.order.orderJoin.is_goodslist==1&&this.order.role==1&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==2))){
					this.dqr=true;
					this.loading=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.is_goodslist==0&&this.order.orderInfo.is_goodslist==1&&this.order.role==2&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==1))){
					this.dqr=true;
					this.loading=true;
				}
				
			},
			hwqd() {
				uni.navigateTo({
					url: "/pages/textbook/hwqd?order_id=" + this.order.orderInfo.id + "&join_order_id=" +
						this.order.orderInfo.join_order_id
				})
			},
			yiqueren() {
				if(this.order.orderInfo.type == 'goods'&&this.order.orderInfo.is_goodslist==1&&this.order.orderJoin.is_goodslist==1){
					this.yqr=true;
				}else if(this.order.orderInfo.type == 'crossborder'&&this.order.orderJoin.is_goodslist==1&&this.order.orderInfo.is_goodslist==1){
					this.yqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderInfo.is_goodslist==1&&this.order.role==1&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==2))){
					this.yqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.is_goodslist==1&&this.order.role==2&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==1))){
					this.yqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.is_goodslist==1&&this.order.orderInfo.is_goodslist==1&&this.order.role==2&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==2))){
					this.yqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.is_goodslist==1&&this.order.role==1&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==1))){
					this.yqr=true;
				}
				console.log(this.yqr)
			},
			duifangyiqueren() {
				if(this.order.orderInfo.type == 'goods'&&this.order.orderInfo.is_goodslist==1&&this.order.role==2&&this.order.orderJoin.goods_list){
					this.dfyqr=true;
				}else if(this.order.orderInfo.type == 'crossborder'&&this.order.orderJoin.is_goodslist==1&&this.order.role==1&&this.order.orderInfo.goods_list){
					this.dfyqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderInfo.is_goodslist==1&&this.order.role==2&&this.order.orderJoin.goods_list&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==2))){
					this.dfyqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.is_goodslist==1&&this.order.role==1&&this.order.orderInfo.goods_list&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==1))){
					this.dfyqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderJoin.goods_list&&this.order.role==1&&(this.order.orderInfo.release_info.release_type==1||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==2))){
					this.dfyqr=true;
				}else if(this.order.orderInfo.type == 'transport'&&this.order.orderInfo.goods_list&&this.order.role==2&&(this.order.orderInfo.release_info.release_type==2||(this.order.orderInfo.release_info.release_type==3&&this.order.orderInfo.release_info.human_type==1))){
					this.dfyqr=true;
				}
			},
			confirmGoodsList(role) {
				this.loading = false;
				uni.showModal({
					title: this.$t('确认货物清单'),
					content: this.$t("是否确认货物清单"),
					confirmText: this.$t('是'), // 修改确认按钮文字
					cancelText: this.$t('否'),
					success: (res) => {
						if (res.confirm) {
							const that = this
							that.$u.api.order.confirmGoodsList({
								role: role,
								order_id: this.order.orderInfo.id,
								join_order_id: this.order.orderInfo.join_order_id,
							}).then(res => {
								that.$u.toast(this.$t('操作成功'))
								that.order.orderInfo.is_goodslist = 1
								that.loading = true;
								that.$emit('on-oversize', 1);
								
							})
							// 用户点击了确定，执行相应的逻辑
						} else if (res.cancel) {
							// 用户点击了取消，执行相应的逻辑
							this.loading = true;
						}

					}
				})
				this.loading = true;
			},
			upload(e, data) {
				
				if(this.plat!='app'){
					this.goods_list = data[0].url
					this.showDataList = data
				}else{
					this.goods_list = data.url
					this.showDataList = [data]
				}
				var that = this;
				if(that.goods_list==''){
					that.$u.toast(this.$t('文件格式不正确'))
					return;
				}
				
				this.loading = false
				if (e && data) {
					this.$u.api.order.upgoodsList({
						goods_list: this.goods_list,
						order_id: this.order.orderInfo.id,
						join_order_id: this.order.orderInfo.join_order_id,
						role: this.order.role,
						type: this.order.orderInfo.type
					}).then(res => {
						that.$emit('on-oversize', 1);
					})
				}
				this.loading = true
			},
			//下载文件
			downLoadFile(url) {
				const that = this
				uni.showLoading({
					title: "download...",
					mask: true
				})
				console.log('下载链接', this.IMAGE_URL + url)
				var downloadTask = uni.downloadFile({
					url: that.IMAGE_URL + url,
					success(res) {
						uni.hideLoading()
						console.log('tempFilePath', res.tempFilePath)
						const tempFilePath = res.tempFilePath
						uni.openDocument({
							filePath: tempFilePath,
							showMenu: true,
							success: function(file) {
								console.log('file-success', file);
							}
						});
					},
				})
				downloadTask.onProgressUpdate(({
					progress,
					totalBytesWritten,
					totalBytesExpectedToWrite
				}) => {
					if (progress === 100) {
						downloadTask.offProgressUpdate();
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/orderDetail.scss";
	.touming{ background: transparent !important; }
	
</style>